package com.yellow.orderservice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yellow.orderservice.entity.Order;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface OrderMapper extends BaseMapper<Order> {

    //通过用户id查询对应的订单
    @Select("SELECT o.* FROM orders o JOIN customer_orders uo ON o.order_id = uo.order_id WHERE uo.customer_id = #{id};")
    List<Order> selectOrderListByUserId(@Param("id") Integer userId);

    @Select("SELECT courier_name FROM orders where order_id = #{orderId};")
    String getCourierNameByOrderId(@Param("orderId") Integer orderId);

    //插入customer_orders
    @Select("INSERT INTO customer_orders (customer_id, order_id,id) VALUES (#{customerId}, #{orderId},#{id});")
    void insertCustomerOrders(@Param("customerId") Integer customerId, @Param("orderId") Integer orderId, @Param("id") Long id);

    @Select("SELECT COUNT(*) FROM customer_orders;")
    Integer countCustomerOrders();
}

